package com.hunteron;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import com.hunteron.common4s.jdk.JunitConsoleOut;
import com.hunteron.common4s.jdk.security.SecurityUtil;

public class TestFile {
    
    private static void readFrom(String urlString, FileOutputStream fos) throws Exception {
        URL url = new URL(urlString);  
        HttpURLConnection httpUrlConn = (HttpURLConnection) url.openConnection();  
        httpUrlConn.setDoInput(true);  
        httpUrlConn.setRequestMethod("GET");  
        httpUrlConn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
        // 获取输入流  
        InputStream inputStream = httpUrlConn.getInputStream();  
        byte[] content = new byte[1024];
        int b = 0;
        while ((b = inputStream.read(content)) != -1) {
            fos.write(content, 0, b);
        }
    }

    public static void main(String[] args) throws Exception {
        String url = "https://vf1.336t.com/20181104/69ca51b18a16f5e62f2a52300af57f37/hls/hls-720p{}.ts";
        
        FileOutputStream fos = new FileOutputStream(new File("/Users/wjyuian/Downloads/test.ts"));
        
        int i = 10;
        
        try {
            while(i < 10000) {
                System.out.println(i);
                readFrom(JunitConsoleOut.consoleLine(url, i ++), fos);
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        
        
        fos.close();
    }
}
